from django import forms
from django.utils.translation import gettext_lazy as _
from . import models
from lib.django.forms import CrispyModelForm, HiddenDeleteFormSet, create_readonly_modelformset
from django.forms import modelformset_factory
from media.lib.forms import FileUploadModelForm, FileUploadField

class ProjectForm(CrispyModelForm):
    class Meta:
        model = models.Project
        exclude = ['user']


class PlanForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("附件"),
    )
    
    class Meta:
        model = models.Plan
        exclude = ['project']


class InitiationDataForm(FileUploadModelForm):
    file = FileUploadField(
        multiple=False,
        label=_("立项申请表"),
        # help_text=_("仅限签字扫描的PDF版"),
    )
    
    class Meta:
        model = models.InitiationData
        exclude = [ 'project' ]


class EthicalReviewForm(FileUploadModelForm):
    file = FileUploadField(
        multiple=False,
        label=_("伦理批件文件"),
        # help_text=_("仅限签字扫描的PDF版"),
    )
    
    class Meta:
        model = models.EthicalReview
        exclude = ['project']
        
        
class HumanGeneticResouceForm(FileUploadModelForm):
    file = FileUploadField(
        label=_("北大六院人遗年度总结(年度)"),
    )
    
    class Meta:
        model = models.HumanGeneticResource
        exclude = ['project']

        
class HGRInternationalCooperationForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("附件"),
    )
    
    class Meta:
        model = models.HGRInternationalCooperation
        exclude = ['HGR']

HGRInternationalCooperationFormSet = modelformset_factory(
    models.HGRInternationalCooperation,
    form=HGRInternationalCooperationForm,
    extra=1,
    can_delete=True,
    formset=HiddenDeleteFormSet
)

HGRInternationalCooperationReadOnlyFormSet = create_readonly_modelformset(
    models.HGRInternationalCooperation,
    exclude_fields=['HGR'],
    form_class=HGRInternationalCooperationForm
)

class HGRCollectionForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("附件"),
    )
    
    class Meta:
        model = models.HGRCollection
        exclude = ['HGR']

HGRCollectionFormSet = modelformset_factory(
    models.HGRCollection,
    form=HGRCollectionForm,
    extra=1,
    can_delete=True,
    formset=HiddenDeleteFormSet
)

HGRCollectionReadOnlyFormSet = create_readonly_modelformset(
    models.HGRCollection,
    exclude_fields=['HGR'],
    form_class=HGRCollectionForm
)

class HGRStorageForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("附件"),
    )
    
    class Meta:
        model = models.HGRStorage
        exclude = ['HGR']

HGRStorageFormSet = modelformset_factory(
    models.HGRStorage,
    form=HGRStorageForm,
    extra=1,
    can_delete=True,
    formset=HiddenDeleteFormSet
)

HGRStorageReadOnlyFormSet = create_readonly_modelformset(
    models.HGRStorage,
    exclude_fields=['HGR'],
    form_class=HGRStorageForm
)

class HGRMaterialExportForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("附件"),
    )
    
    class Meta:
        model = models.HGRMaterialExport
        exclude = ['HGR']

HGRMaterialExportFormSet = modelformset_factory(
    models.HGRMaterialExport,
    form=HGRMaterialExportForm,
    extra=1,
    can_delete=True,
    formset=HiddenDeleteFormSet
)

HGRMaterialExportReadOnlyFormSet = create_readonly_modelformset(
    models.HGRMaterialExport,
    exclude_fields=['HGR'],
    form_class=HGRMaterialExportForm
)

class HGRDataFilingForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("附件"),
    )
    
    class Meta:
        model = models.HGRDataFiling
        exclude = ['HGR']

HGRDataFilingFormSet = modelformset_factory(
    models.HGRDataFiling,
    form=HGRDataFilingForm,
    extra=1,
    can_delete=True,
    formset=HiddenDeleteFormSet
)

HGRDataFilingReadOnlyFormSet = create_readonly_modelformset(
    models.HGRDataFiling,
    exclude_fields=['HGR'],
    form_class=HGRDataFilingForm
)

class ContractForm(CrispyModelForm):
    class Meta:
        model = models.Contract
        exclude = ['project']

class BeforeImplementForm(CrispyModelForm):
    class Meta:
        model = models.BeforeImplement
        exclude = ['project']

class MaterialForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("器材质控证明文件"),
    )
    class Meta:
        model = models.Material
        exclude = ['project']

class BeginningForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("其它文件"),
    )

    class Meta:
        model = models.Beginning
        exclude = ['project']

class ImplementForm(FileUploadModelForm):
    files = FileUploadField(
        multiple=True,
        label=_("其它文件"),
    )
    
    class Meta:
        model = models.Implement
        exclude = ['project']

class QualityControlForm(FileUploadModelForm):
    file = FileUploadField(
        multiple=False,
        label=_("质控报告"),
        # help_text=_("仅限签字扫描的PDF版"),
    )
    class Meta:
        model = models.QualityControl
        exclude = ['project']

class FinishForm(FileUploadModelForm):
    quality_control_report = FileUploadField(
        multiple=False,
        label=_("质控报告"),
    )

    summary_report_file = FileUploadField(
        multiple=False,
        label=_("总结报告"),
    )
     
    sub_center_summary_report_file = FileUploadField(
        multiple=False,
        label=_("分中心小结表"),
    )

    class Meta:
        model = models.Finish
        exclude = ['project']

class ExaminationForm(FileUploadModelForm):
    file = FileUploadField(
        multiple=True,
        label=_("问题、整改文件"),
    )
    
    class Meta:
        model = models.Examination
        exclude = ['project']
